import Vue from 'vue'
import Router from 'vue-router'
import routes from './routes.js'


Vue.use(Router)

const router = new Router({
    routes
})

router.beforeEach((to, from, next) => {
    const app = router.app
    const store = app.$options.store
    const auth = store.state.auth
    if (!auth && to.path.indexOf('/login') == -1) {
        next('/login')
    } else {
        next();
    }
})

export default router;
